
using System;
using System.IO;

namespace wc_gui_input
{
	
	public class add_page : Gtk.Window
	{
		protected Gtk.Entry entry_title;
		protected Gtk.TextView text_content;
		protected Gtk.Button but_add;

		bool new_page;
		string page;
		string category;

		
		public add_page(string filename, string cat) : base("")
		{
			Stetic.Gui.Build(this, typeof(wc_gui_input.add_page));
			new_page=true;
			if (filename != "") {
				// given filename, not a new page
				new_page=false;
				category=cat;
				page=filename;
				init_widgets();
			}
		}

		protected virtual void init_widgets() {
			TextReader infile;// infile is page ( category --> page )
			try {
	 			infile = new StreamReader(page); // file to read from 
	    	} catch(FileNotFoundException exc) { 
	      		Console.WriteLine(exc.Message); 
	   	   		return; 
    		}
    		
    		String line;
			entry_title.Text=category;
			Console.WriteLine(category);
			
			for (int i=1; i<61; i++) {// start at 1 since gedit starts lines @ 1
				line=infile.ReadLine();
				if (i == 60) { // this is the line with the content
					Console.WriteLine(line);
					text_content.Buffer.Text=line;
				}
			}
		}
	
		protected virtual void OnButAddClicked(object sender, System.EventArgs e)
		{
			
		}
	}
	
}
